package com.sywb.chuangyebao.view;

import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;
import com.sywb.chuangyebao.utils.Utils;
import com.umeng.analytics.MobclickAgent;

import org.bining.footstone.presenter.BasePresenter;
import org.bining.footstone.view.BaseActivity;

import java.util.Random;

public abstract class BaseStatisticsActivity<T extends BasePresenter> extends BaseActivity<T> {

    private long wpid;
    private long stime;

    @Override
    protected void onStart() {
        super.onStart();
        stime = System.currentTimeMillis();
        wpid = stime * 100 + Utils.getNum(10, 100);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isStatisticsPage()) {
            MobclickAgent.onPageStart(getStatisticsIdentity()); //手动统计页面
            stime = System.currentTimeMillis();
            getStatisticsPath(getStatisticsIdentity());
        }
        MobclickAgent.onResume(this); //统计时长
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (isStatisticsPage()) {
            MobclickAgent.onPageEnd(getStatisticsIdentity()); //手动统计页面，必须保证 onPageEnd 在 onPause 之前调用，因为SDK会在 onPause 中保存onPageEnd统计到的页面数据。
            getStatisticsTime();
        }
        MobclickAgent.onPause(this); //统计时长
    }

    public boolean isStatisticsPage() {
        return true;
    }

    public String getStatisticsIdentity() {
        return this.getClass().getName();
    }

    public int getPageNum() {
        return 0;
    }

    public int getProjectId() {
        return 0;
    }

    public int getNewsId() {
        return 0;
    }

    public void getStatisticsPath(String pageName) {
        HttpUtils.getStatisticsPath(wpid, pageName, getPageNum(), getProjectId(), getNewsId(), new HttpCallback<String>() {
            @Override
            public void onSuccess(String s) {

            }
        });
    }

    public void getStatisticsTime() {
        HttpUtils.getStatisticsTime(wpid, stime, System.currentTimeMillis(), new HttpCallback<String>() {
            @Override
            public void onSuccess(String s) {

            }
        });
    }

}
